Skip to content

feat: notify on time changes in MockTimeSystem#964

Merged
vbreuss merged 8 commits intomainfrom
topic/add-starttime-to-timeprovider
Mar 13, 2026
Merged

feat: notify on time changes in MockTimeSystem#964
vbreuss merged 8 commits intomainfrom
topic/add-starttime-to-timeprovider

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Mar 13, 2026

This pull request introduces significant improvements to the time system mocking infrastructure, focusing on extensibility and notification capabilities. The main changes include introducing an ITimeProviderFactory for more flexible creation of time providers, enhancing notification support for time changes, and updating related APIs and documentation accordingly.

Time provider extensibility and notification improvements:

  • Introduced the ITimeProviderFactory interface and updated TimeProvider.Now(), TimeProvider.Random(), and TimeProvider.Use() to return factories instead of direct time providers, allowing for more flexible and testable time provider creation.
  • Updated the MockTimeSystem class to accept an ITimeProviderFactory and to use a callback for time change notifications. The previous constructor accepting ITimeProvider will be marked as obsolete.

Time change notification enhancements:

  • Added a new TimeChanged callback to the INotificationHandler interface and implemented it in NotificationHandler, allowing clients to be notified whenever the mocked time changes.
  • Updated TimeProviderMock to support the new time change notification mechanism and expose the StartTime property, reflecting the initial time at which the provider was created.

@vbreuss vbreuss self-assigned this Mar 13, 2026
Copilot AI review requested due to automatic review settings March 13, 2026 15:10
@vbreuss vbreuss added the enhancement New feature or request label Mar 13, 2026
@vbreuss vbreuss force-pushed the topic/add-starttime-to-timeprovider branch from 67690db to b51f3cd Compare March 13, 2026 15:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an explicit StartTime concept to the MockTimeSystem time provider so callers can reliably retrieve the initial simulated time even after advancing the clock.

Changes:

  • Introduce StartTime on ITimeProvider.
  • Persist the initial time in TimeProviderMock via a read-only StartTime property.
  • Add a unit test asserting StartTime remains the initial value after time advances.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

File Description
Tests/Testably.Abstractions.Testing.Tests/MockTimeSystemTests.cs Adds coverage for TimeProvider.StartTime being set to the initial time and remaining stable.
Source/Testably.Abstractions.Testing/TimeSystem/TimeProviderMock.cs Implements StartTime and initializes it from the initial _now.
Source/Testably.Abstractions.Testing/TimeSystem/ITimeProvider.cs Extends the public time provider contract with StartTime and XML documentation.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 13, 2026

Test Results

12 tests  ±0   12 ✅ ±0   1s ⏱️ -1s
 1 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 06057d3. ± Comparison against base commit fd3a7ab.

♻️ This comment has been updated with latest results.

@vbreuss vbreuss changed the title feat: add StartTime to the time provider of the MockTimeSystem feat: notify on time changes in MockTimeSystem Mar 13, 2026
@vbreuss vbreuss force-pushed the topic/add-starttime-to-timeprovider branch from 4b01dce to e200b02 Compare March 13, 2026 16:33
@vbreuss vbreuss enabled auto-merge (squash) March 13, 2026 20:21
@sonarqubecloud
Copy link
Copy Markdown

@vbreuss vbreuss merged commit 4ed0ce0 into main Mar 13, 2026
12 of 13 checks passed
@vbreuss vbreuss deleted the topic/add-starttime-to-timeprovider branch March 13, 2026 21:02
@github-actions
Copy link
Copy Markdown

This is addressed in release v6.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request state: released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants